<?php

// TITLE: foh
// FILE: foh.php
// AUTHOR: dantira
// CREATED: Mar 21, 2015, 4:55:04 PM
?>

		public function createFriendsOfHabitat($eventId, $contactId) {
			global $con;
			$sql = 'INSERT INTO friends_of_habitat (event_id, contact_id) VALUES (' . $eventId . ', ' . $contactId . ')';
			$this->open();
			$result = mysqli_query($con, $sql);
			$id = ($result) ? mysqli_insert_id($con) : $result;
			$this->close();
			return $id;
		}// end function

		public function readFriendsOfHabitat($id) {
			global $con;
			$sql = 'SELECT * FROM friends_of_habitat WHERE id = ' . $id;
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$result = mysqli_fetch_array($results);
				$friendsOfHabitat = new FriendsOfHabitat();
				$friendsOfHabitat->setEventId($this->readEvent($result[0]));
				$friendsOfHabitat->setContactId($this->readContact($result[1]));
			} else {
				$friendsOfHabitat = false;
			}
			return $friendsOfHabitat;
		}// end function

		public function updateFriendsOfHabitat($eventId, $contactId) {
			global $con;
			$sql = 'UPDATE friends_of_habitat SET event_id = ' . $event_id . ', contact_id = ' . $contactId . ' WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function deleteFriendsOfHabitat($id) {
			global $con;
			$sql = 'DELETE FROM friends_of_habitat WHERE event_id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function listFriendsOfHabitat() {
			global $con;
			$sql = 'SELECT * FROM friends_of_habitat';
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$friendsOfHabitats = array();
				while ($result = mysqli_fetch_array($results)) {
					$friendsOfHabitat = new FriendsOfHabitat();
					$friendsOfHabitat->setEventId($this->readEvent($result[0]));
					$friendsOfHabitat->setContactId($this->readContact($result[1]));
					$friendsOfHabitats[] = $friendsOfHabitat;
				}// end while
			} else {
				$friendsOfHabitats = false;
			}
			return $friendsOfHabitats;
		}// end function
